import java.io.File
import java.io.IOException

object GenXMLDoc {
    val rt=Runtime.getRuntime()
    @Throws(IOException::class)
    @JvmStatic
    fun main(args: Array<String>) {
        val JAVA_HOME = "/usr/lib/jvm/java-1.8.0-openjdk-amd64"
        val cp=File("libs").listFiles().joinToString(":")
        val shFile=File("./genxml.sh")
        shFile.createNewFile()
        shFile.writer().use {
            var cmd =
                "rm bin -rf && $JAVA_HOME/bin/javadoc -cp $cp -public -doclet BADoclet -docletpath docs/ -b4atarget docs/tyme4j.xml src/main/java/top/xlz999/tyme/*.java"
            it.write(cmd+"\n")
            cmd="mkdir bin && $JAVA_HOME/bin/javac -d bin -cp $cp src/main/java/top/xlz999/tyme/*.java"
            it.write(cmd+"\n")
            cmd= "cd bin && $JAVA_HOME/bin/jar -cvf ../docs/tyme4j.jar ./ && cp ../libs/tyme4j-1.1.2.jar ../docs/"
            it.write(cmd+"\n")
            it.flush()
        }
        rt.exec("bash genxml.sh")
    }

}
